package com.fita.admin.entity.content;


import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Map;

/**
 * @author LZJ
 *
 */
public class CouponBatchSearch implements QueryBuilder {
    
    /** 优惠券名称 */
    private String templateName;
    
    /** 批次名称 */
    private String name;
    
    /** 截止日开始时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;
    
    /** 截止日结束时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;
    

    private QueryFilter filter;
    
    /**
     * default constructor
     */
    public CouponBatchSearch() {
        
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if(filter == null || refresh) {
            filter =  new QueryFilter().addLike("templateName", templateName)
                                  .addLike("name", name)
                                  .addDateBetween("effectiveEndDate", beginDate, endDate);
        }

        return filter;
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM CouponBatch " + getPreparedFilter(false).whereSentence() ;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }


    /**
     * @return the templateName
     */
    public String getTemplateName() {
        return templateName;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the beginDate
     */
    public Date getBeginDate() {
        return beginDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @param templateName the templateName to set
     */
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param beginDate the beginDate to set
     */
    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

	@Override
	public QueryOrder getOrder() {
		// TODO Auto-generated method stub
		return null;
	}

  

}